package org.hh128.jiMuBianCheng;

import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.graphics.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.util.*;
import java.text.*;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import java.util.ArrayList;
import android.widget.LinearLayout;
import android.widget.Button;
import android.widget.ImageView;
import android.content.Intent;
import android.net.Uri;
import android.media.MediaPlayer;
import android.animation.ObjectAnimator;
import android.view.animation.LinearInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.BounceInterpolator;
import java.util.Timer;
import java.util.TimerTask;
import android.view.View;

public class MainActivity extends AppCompatActivity {
	
	private Timer _timer = new Timer();
	
	private Toolbar _toolbar;
	private boolean can_up = false;
	private String d = "";
	private boolean can_play = false;
	
	private ArrayList<String> images = new ArrayList<>();
	
	private LinearLayout linear1;
	private LinearLayout linear2;
	private LinearLayout linear3;
	private Button button1;
	private Button button2;
	private Button about;
	private Button button4;
	private ImageView imageview1;
	private ImageView effect;
	private ImageView plane;
	
	private Intent intent = new Intent();
	private MediaPlayer bgm;
	private ObjectAnimator android = new ObjectAnimator();
	private TimerTask time;
	private MediaPlayer wwlcome;
	@Override
	protected void onCreate(Bundle _savedInstanceState) {
		super.onCreate(_savedInstanceState);
		setContentView(R.layout.main);
		initialize(_savedInstanceState);
		initializeLogic();
	}
	
	private void initialize(Bundle _savedInstanceState) {
		
		_toolbar = (Toolbar) findViewById(R.id._toolbar);
		setSupportActionBar(_toolbar);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		getSupportActionBar().setHomeButtonEnabled(true);
		_toolbar.setNavigationOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _v) {
				onBackPressed();
			}
		});
		linear1 = (LinearLayout) findViewById(R.id.linear1);
		linear2 = (LinearLayout) findViewById(R.id.linear2);
		linear3 = (LinearLayout) findViewById(R.id.linear3);
		button1 = (Button) findViewById(R.id.button1);
		button2 = (Button) findViewById(R.id.button2);
		about = (Button) findViewById(R.id.about);
		button4 = (Button) findViewById(R.id.button4);
		imageview1 = (ImageView) findViewById(R.id.imageview1);
		effect = (ImageView) findViewById(R.id.effect);
		plane = (ImageView) findViewById(R.id.plane);
		
		button1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				if (wwlcome.isPlaying()) {
					wwlcome.pause();
					intent.setClass(getApplicationContext(), EditorActivity.class);
					startActivity(intent);
				}
				else {
					intent.setClass(getApplicationContext(), EditorActivity.class);
					startActivity(intent);
				}
			}
		});
		
		button2.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				intent.setClass(getApplicationContext(), GgameActivity.class);
				startActivity(intent);
			}
		});
		
		about.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				can_up = false;
				time.cancel();
				if (wwlcome.isPlaying()) {
					wwlcome.pause();
					intent.setClass(getApplicationContext(), AboutActivity.class);
					startActivity(intent);
				}
				else {
					intent.setClass(getApplicationContext(), AboutActivity.class);
					startActivity(intent);
				}
			}
		});
		
		button4.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				if (wwlcome.isPlaying()) {
					wwlcome.pause();
					intent.setClass(getApplicationContext(), CustomlanguageActivity.class);
					startActivity(intent);
				}
				else {
					intent.setClass(getApplicationContext(), CustomlanguageActivity.class);
					startActivity(intent);
				}
			}
		});
		
		effect.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View _view) {
				SketchwareUtil.showMessage(getApplicationContext(), "干嘛点我😅");
			}
		});
	}
	private void initializeLogic() {
		intent.putExtra("back", "ooo");
		SketchwareUtil.showMessage(getApplicationContext(), "创建");
		wwlcome = MediaPlayer.create(getApplicationContext(), R.raw.welcome);
		can_up = true;
		if (wwlcome.isPlaying()) {
			wwlcome.pause();
		}
		else {
			wwlcome.start();
		}
		time = new TimerTask() {
			@Override
			public void run() {
				runOnUiThread(new Runnable() {
					@Override
					public void run() {
						if (can_up) {
							effect.setRotation((float)(effect.getRotation() + 20));
						}
					}
				});
			}
		};
		_timer.scheduleAtFixedRate(time, (int)(0), (int)(500));
	}
	
	@Override
	protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
		super.onActivityResult(_requestCode, _resultCode, _data);
		
		switch (_requestCode) {
			
			default:
			break;
		}
	}
	
	@Override
	public void onResume() {
		super.onResume();
		SketchwareUtil.showMessage(getApplicationContext(), "恢复");
	}
	@Deprecated
	public void showMessage(String _s) {
		Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
	}
	
	@Deprecated
	public int getLocationX(View _v) {
		int _location[] = new int[2];
		_v.getLocationInWindow(_location);
		return _location[0];
	}
	
	@Deprecated
	public int getLocationY(View _v) {
		int _location[] = new int[2];
		_v.getLocationInWindow(_location);
		return _location[1];
	}
	
	@Deprecated
	public int getRandom(int _min, int _max) {
		Random random = new Random();
		return random.nextInt(_max - _min + 1) + _min;
	}
	
	@Deprecated
	public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
		ArrayList<Double> _result = new ArrayList<Double>();
		SparseBooleanArray _arr = _list.getCheckedItemPositions();
		for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
			if (_arr.valueAt(_iIdx))
			_result.add((double)_arr.keyAt(_iIdx));
		}
		return _result;
	}
	
	@Deprecated
	public float getDip(int _input){
		return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
	}
	
	@Deprecated
	public int getDisplayWidthPixels(){
		return getResources().getDisplayMetrics().widthPixels;
	}
	
	@Deprecated
	public int getDisplayHeightPixels(){
		return getResources().getDisplayMetrics().heightPixels;
	}
	
}
